from celery import Celery
from celery.schedules import crontab
from backend.config.config import settings



REDIS_URL = f"redis://:{settings.REDIS_PASSWORD}@{settings.REDIS_HOST}:{settings.REDIS_PORT}/1"

celery_app = Celery(
    "app",
    broker=REDIS_URL,
    backend=REDIS_URL
)

celery_app.autodiscover_tasks(["backend.tasks"])


# 设置时区为北京时间
celery_app.conf.timezone = 'Asia/Shanghai'
celery_app.conf.enable_utc = False

celery_app.conf.beat_schedule = {
    "sync_query_rapid": {
        "task": "app.tasks.task2.sync_query_rapid",
        "schedule": crontab(minute="*/5"),  # 每5分钟执行一次
        "args": ("失败",),
    },
    "print-hello-every-60-seconds": {
        "task": "app.tasks.task2.say_hello",
        "schedule": 60.0,
        "args": ("FastAPI user",),
    },
    "run-every-day-at-7am": {
        "task": "app.tasks.task2.daily_report",
        "schedule": crontab(hour=7, minute=0),
    },
}
